--[[
Copyright:www.vxinyou.com
Author:Hongru
CreateTime:2015-01-04
Description:CCLayerRGBA
--]]

local LayerRGBA = Class("lua/cc/clsLayer.lua"):Inherit()

function LayerRGBA:create(args)
	self._root = CCLayerRGBA:create()
end

function LayerRGBA:doDistinctConfig()
	if not self.args then
		return 
	end
	if self.args.displayedOpacity then
		self:updateDisplayedOpacity(self.args.displayedOpacity)
	end
	if self.args.cascadeOpacityEnabled then
		self:setCascadeOpacityEnabled(self.args.cascadeOpacityEnabled)
	end
	if self.args.color then
		self:setColor(self.args.color)
	end
	if self.args.displayedColor then
		self:updateDisplayedColor(self.args.displayedColor)
	end
	if self.args.cascadeColorEnabled then
		self:setCascadeColorEnabled(self.args.cascadeColorEnabled)
	end
	if self.args.opacityModifyRGB then
		self:setOpacityModifyRGB(self.args.opacityModifyRGB)
	end
end
function LayerRGBA:setSelfConfig(Type, newConfig)
	assert(Type)
	assert(newConfig)
	local configType = Type
	if configType == "updateDisplayedOpacity" then
		self.args.displayedOpacity = newConfig.displayedOpacity
	elseif configType == "setCascadeOpacityEnabled" then
		self.args.cascadeOpacityEnabled = newConfig.cascadeOpacityEnabled
	elseif configType == "setColor" then
		self.args.color = newConfig.color
	elseif configType == "updateDisplayedColor" then
		self.args.displayedColor = newConfig.displayedColor
	elseif configType == "setCascadeColorEnabled" then
		self.args.cascadeColorEnabled = newConfig.cascadeColorEnabled
	elseif configType == "setOpacityModifyRGB" then
		self.args.opacityModifyRGB = newConfig.opacityModifyRGB
	end
end

function LayerRGBA:delete()
	if self._root then
		self._root:delete()
	end
end

function LayerRGBA:getDisplayedOpacity()
	if self._root then
		return self._root:getDisplayedOpacity()
	end
end

function LayerRGBA:updateDisplayedOpacity(value)
	if self._root then
		self._root:updateDisplayedOpacity(value)
		self:setSelfConfig("updateDisplayedOpacity", {displayedOpacity = value})
	end
	
end

function LayerRGBA:isCascadeOpacityEnabled()
	if self._root then
		return self._root:isCascadeOpacityEnabled()
	end
end

function LayerRGBA:setCascadeOpacityEnabled(bValue)
	if self._root then
		self._root:setCascadeOpacityEnabled(bValue)
		self:setSelfConfig("setCascadeOpacityEnabled", {cascadeOpacityEnabled = bValue})
	end
end

function LayerRGBA:getColor()
	if self._root then
		return self._root:getColor()
	end
end

function LayerRGBA:getDisplayedColor()
	if self._root then
		return self._root:getDisplayedColor()
	end
end

--ccc3(r,g,b)
function LayerRGBA:setColor(color)
	if self._root then
		self._root:setColor(color)
		self:setSelfConfig("setColor", {color = color})
	end
end

--ccc3(r,g,b)
function LayerRGBA:updateDisplayedColor(color)
	if self._root then
		self._root:updateDisplayedColor(color)
		self:setSelfConfig("updateDisplayedColor", {displayedColor = color})
	end
end

function LayerRGBA:isCascadeColorEnabled()
	if self._root then
		return self._root:isCascadeColorEnabled()
	end
end

function LayerRGBA:setCascadeColorEnabled(bValue)
	if self._root then
		self._root:setCascadeColorEnabled(bValue)
		self:setSelfConfig("setCascadeColorEnabled", {cascadeColorEnabled = bValue})
	end
end

 function LayerRGBA:setOpacityModifyRGB(bValue)
	if self._root then
		self._root:setOpacityModifyRGB(bValue)
		self:setSelfConfig("setOpacityModifyRGB", {opacityModifyRGB = bValue})
	end
end

function LayerRGBA:isOpacityModifyRGB()
	if self._root then
		return self._root:isOpacityModifyRGB()
	end
end

function getClass()
	return LayerRGBA
end